<?php
include ("conn.php");
$skey = $_POST['skey'];
$pid = $_POST['pid'];
//验证skey是否存在
$sql="SELECT * FROM user WHERE thirdSession='".$skey."'";
$result = $conn->query($sql);
if ($result->num_rows == 0) {exit('{"code":450}');}
$row = $result->fetch_assoc();
$uid = $row['id'];
//检查这个skey对应的uid是否已经收藏过文档
$sql="SELECT * FROM collection WHERE uid=".$uid." AND pid=".$pid;
$result = $conn->query($sql);
if ($result->num_rows == 1) {
	//点了就给他删掉 
	$sql="DELETE FROM collection WHERE uid=".$uid." AND pid=".$pid;
	$result = $conn->query($sql);
	exit('{"code":451}');
}
//增加一条收藏记录
$sql="INSERT INTO collection (uid, pid) VALUES (".$uid.",".$pid.")";
$result = $conn->query($sql);
//返回收藏成功信息
echo '{"code":452}';
?>